package com.talkyun.openx.validator.impl;

import com.talkyun.openx.validator.annotation.NumberValidator;

import java.lang.annotation.Annotation;

public class NumberValidatorImpl extends AbstractValidator {

    @Override
    public String validate(Annotation ann, String argName, Object argVal) {
        return doValidate((NumberValidator) ann, argName, (Number) argVal);
    }

    private String doValidate(NumberValidator sv, String name, Number val) {
        if (sv.notNull() && val == null) {
            return "参数不能为空!";
        }
        if (val.longValue() < sv.min()) {
            return "参数不能小于：" + sv.min() + "!";
        }
        if (val.longValue() > sv.max()) {
            return "参数不能大于：" + sv.max() + "!";

        }
        return null;
    }
}